using GameUsingAspNetMVCandJQueryUI.Core.Service;
using StructureMap;
using StructureMap.Graph;

namespace GameUsingAspNetMVCandJQueryUI.DependencyResolution
{
    public class StructureMapConfiguration
    {
        private static bool _dependenciesRegistered;
        private static readonly object sync = new object();

        private static void RegisterDependencies()
        {
            ObjectFactory.Initialize(x => x.Scan(y =>
            {
                y.AssemblyContainingType(typeof(AnimalsService));
                y.With<DefaultConventionScanner>();
            }));
        }

        public static void Configure()
        {
            if (!_dependenciesRegistered)
            {
                lock (sync)
                {
                    if (!_dependenciesRegistered)
                    {
                        RegisterDependencies();
                        _dependenciesRegistered = true;

                    }
                }
            }
        }
    }
}